package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.entity.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author with葡萄成熟时
 * @version 1.0
 */
@RestController
@Slf4j
@Api(tags = "购物车相关接口")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;


    /**
     * @description: 添加购物车
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午9:20 2024/11/14
     */
    @ApiOperation("添加购物车")
    @PostMapping("/user/shoppingCart/add")
    public Result addShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {

        shoppingCartService.addShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /**
     * @description: 查看购物车
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午9:33 2024/11/14
     */
    @ApiOperation("查看购物车")
    @GetMapping("/user/shoppingCart/list")
    public Result<List<ShoppingCart>> listShoppingCart() {

        List<ShoppingCart> list=  shoppingCartService.listShoppingCart();
        return Result.success(list);
    }

    /**
     * @description: 删除购物车中一个商品
     * @param:
     * @return:
     * @author Wait葡萄成熟时
     * @date: 下午9:49 2024/11/14
     */
    @ApiOperation("删除购物车中一个商品")
    @PostMapping("/user/shoppingCart/sub")
    public Result deleteShoppingCart(@RequestBody ShoppingCartDTO shoppingCartDTO) {

        shoppingCartService.deleteShoppingCart(shoppingCartDTO);
        return Result.success();
    }

    /** 
     * @description: 清空购物车
     * @param:
     * @return: 
     * @author Wait葡萄成熟时
     * @date: 下午10:07 2024/11/14
     */
    @ApiOperation("清空购物车")
    @DeleteMapping("/user/shoppingCart/clean")
    public Result cleanShoppingCart() {
        shoppingCartService.cleanAll();

    return Result.success();
    }
}
